Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MSWord compatible RTF sequence for background text color #16035

Merged
merged 3 commits into from
Sep 27, 2023

Conversation

tusharsnx
Copy link
Contributor

@tusharsnx tusharsnx commented Sep 26, 2023

The GenRTF(...) was using \highlight control word for sending background text color in the RTF format during a copy command. This doesn't work correctly, since many applications (E.g. MSWord) don't support full RGB with \highlight, and instead uses an approximation of what is received. For example, rgb(197, 15, 31) becomes rgb(255, 0, 255). Also, the standard way of using background colors is \cbN control word, which isn't supported as per the RTF Spec 1.9.1 in Word.

But it briefly mentioned a workaround at Pg. 23, which seems to work on all the RTF editors I tested:

image

The PR makes the changes to use \chshdng0\chcbpatN for the background coloring.

Also did some refactoring to make the implementation concise.

Validation Steps Performed

Verified that the background is correctly copied on below editors:

  • MSWord
  • WordPad
  • LibreOffice
  • Outlook

@tusharsnx
Copy link
Contributor Author

demo

@DHowett
Copy link
Member

DHowett commented Sep 26, 2023

WOW, great find!

Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glorious!

@DHowett DHowett changed the title Use MSWord compatible RTF sequence for sending background text color Use MSWord compatible RTF sequence for background text color Sep 27, 2023
@DHowett DHowett merged commit 310814b into microsoft:main Sep 27, 2023
14 checks passed
DHowett pushed a commit that referenced this pull request Dec 15, 2023
The `GenRTF(...)` was using `\highlight` control word for sending
background text color in the RTF format during a copy command. This
doesn't work correctly, since many applications (E.g. MSWord) don't
support full RGB with `\highlight`, and instead uses an approximation of
what is received. For example, `rgb(197, 15, 31)` becomes `rgb(255, 0,
255)`. Also, the standard way of using background colors is `\cbN`
control word, which isn't supported as per the [RTF Spec 1.9.1]
in Word.

But it briefly mentioned a workaround at Pg. 23, which seems to work on
all the RTF editors I tested.

The PR makes the changes to use `\chshdng0\chcbpatN` for the background
coloring.

Also did some refactoring to make the implementation concise.

## Validation Steps Performed

Verified that the background is correctly copied on below editors:
- MSWord
- WordPad
- LibreOffice
- Outlook

[RTF Spec 1.9.1]: https://msopenspecs.azureedge.net/files/Archive_References/[MSFT-RTF].pdf

(cherry picked from commit 310814b)
Service-Card-Id: 91349195
Service-Version: 1.19
DHowett pushed a commit that referenced this pull request Jan 23, 2024
The `GenRTF(...)` was using `\highlight` control word for sending
background text color in the RTF format during a copy command. This
doesn't work correctly, since many applications (E.g. MSWord) don't
support full RGB with `\highlight`, and instead uses an approximation of
what is received. For example, `rgb(197, 15, 31)` becomes `rgb(255, 0,
255)`. Also, the standard way of using background colors is `\cbN`
control word, which isn't supported as per the [RTF Spec 1.9.1]
in Word.

But it briefly mentioned a workaround at Pg. 23, which seems to work on
all the RTF editors I tested.

The PR makes the changes to use `\chshdng0\chcbpatN` for the background
coloring.

Also did some refactoring to make the implementation concise.

## Validation Steps Performed

Verified that the background is correctly copied on below editors:
- MSWord
- WordPad
- LibreOffice
- Outlook

[RTF Spec 1.9.1]: https://msopenspecs.azureedge.net/files/Archive_References/[MSFT-RTF].pdf

(cherry picked from commit 310814b)
Service-Card-Id: 91349197
Service-Version: 1.18
@tusharsnx tusharsnx deleted the copypaste branch February 17, 2024 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants